package com.tencent.cloud.iov.util.backdoor;

import android.support.annotation.NonNull;

import com.tencent.cloud.iov.util.backdoor.authority.AuthorityEnum;
import com.tencent.cloud.iov.util.storage.TXSharedPreferencesUtils;

/**
 * @author showxiao
 * @date 2018/8/17
 */
public class DebugBackdoor {

    public static final AuthorityEnum DEFAULT_AUTHORITY;

    private static final String DEBUG_MODE = "debug_mode";

    private static AuthorityEnum sAuthority;

    private static boolean sIsDebugMode;

    static {
        DEFAULT_AUTHORITY = AuthorityEnum.TEST;

        sAuthority = null;
        sIsDebugMode = TXSharedPreferencesUtils.getBoolean(DEBUG_MODE);
    }

    public static boolean isDebugMode() {
        return sIsDebugMode/* || BuildConfig.DEBUG*/;
    }

    public static void setDebugMode(boolean isDebugMode) {
        sIsDebugMode = isDebugMode;
        TXSharedPreferencesUtils.setBoolean(DEBUG_MODE, isDebugMode);
    }

    public static void setAuthority(AuthorityEnum authority) {
        sAuthority = authority;
    }

    public static AuthorityEnum getAuthority() {
        return sAuthority;
    }

    @NonNull
    public static AuthorityEnum getAuthorityOrDefault() {
        return sAuthority == null ? DEFAULT_AUTHORITY : sAuthority;
    }
}
